<script>
import BookShelfApi from "../../api/bookshelf";

export default {
  props: ["bookId"],
  data() {
    return {
      avgRanking: 0,
    };
  },
  methods: {
    async getAvgRanking() {
      try {
        const api = new BookShelfApi();
        let res = await api.avgRankingByBookId(this.bookId);
        let avg = res.data.average ? res.data.average : 0;
        this.avgRanking = avg.toFixed(2);
      } catch (err) {
        console.error(err);
        this.$myMessageBox("应用服务器访问错误！");
      }
    },
  },
  mounted() {
    this.getAvgRanking();
  },
};
</script>

<template>
  <div>
    <div>综合评分:{{ avgRanking }}</div>
  </div>
</template>

<style scoped>
div {
  margin-top: 16px;
}
</style>
